package com.jichangxiu.common.exception;

import com.jichangxiu.common.enums.ErrorType;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.security.core.AuthenticationException;

import java.io.Serializable;

@EqualsAndHashCode(callSuper = true)
public class CaptchaException extends AuthenticationException implements Serializable {

    private static final long serialVersionUID = 1L;

    @Getter
    private Integer code;

    private String message;

    public CaptchaException(String message) {
        super(message);
        this.code = ErrorType.FRAME_EXCEPTION.getCode();
        this.message = message;
    }

    public CaptchaException(String message, Throwable throwable) {
        super(message, throwable);
        this.code = ErrorType.FRAME_EXCEPTION.getCode();
        this.message = message;
    }

    public CaptchaException(ErrorType errorType) {
        super(errorType.getMessage());
        this.code = errorType.getCode();
        this.message = errorType.getMessage();
    }

    public CaptchaException(ErrorType errorType, Throwable throwable) {
        super(errorType.getMessage(), throwable);
        this.code = errorType.getCode();
        this.message = errorType.getMessage();
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}
